#include "stdafx.h"
#include "memstatics.h"

void* udpserver(void* param)
{
	int fd=socket(AF_INET,SOCK_DGRAM,0);
	struct sockaddr_in addr;
	memset(&addr,0,sizeof(struct sockaddr_in));
	addr.sin_port=htons(9999);
	if(0!=bind(fd,(struct sockaddr*)&addr,sizeof(addr)))
	{
		fprintf(stderr,"fail to bind!\n");
		exit(0);
	}

	while(1)
	{
		char buffer[1024]={0};
		socklen_t len=sizeof(struct sockaddr_in);
		struct sockaddr_in caddr;
		bzero(&caddr,sizeof(caddr));
		int retlen=recvfrom(fd,buffer,1024,MSG_WAITALL,(struct sockaddr*)&caddr,&len);
		if(retlen>0)
			printf("recv:%s\n",buffer);
	}
	return NULL;
}
void mainthread()
{
	while(1)
	{
		
	}	
}
int main(int argc,const char* argv[])
{
	memstatics_init();

	pthread_t udpserverthread;
	PTHREAD_CREATE(&udpserverthread,"udpserver",udpserver,0);
	mainthread();
	return 0;
}
